// 生产环境
// export let baseUrl = 'https://h5.helloyouyou.com/'; //正式
export let baseUrl = 'https://d-shucang.bigchun.com/'; //测试
// export let baseUrl = 'https://m.h5zboxart.com/';


// // #ifdef H5
// const hostname = location.hostname;
// // H5开发时使用
// if (hostname.includes('localhost') || hostname.includes('127.0.0.1') || hostname.includes('192.168.')) {
//   baseUrl = '/';
// }
// // 测试环境
// if (hostname.includes('cdn.xtstar.top')) {
//   baseUrl = 'https://cdn.xtstar.top/';
// }
// // #endif


let whiteArr = []
export function http(url, data, method = 'GET') {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			data: {
				...data,
				tokens: uni.getStorageSync('token') || '',
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				token: uni.getStorageSync('token') || ''
			},
			method,
			success: res => {
				if (res.statusCode == 200) {
					if (res.data.code == 1) {
						resolve(res.data.data)
					} else if (res.data.code == 0) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
						})
						reject(res.data.msg)
					} else if (res.data.code == 401) {
						uni.removeStorageSync('token')
						uni.reLaunch({
							url: '/pages/login/index',
						})
						reject(res.data.msg)
					} else if (res.data.code == 403) {
						uni.showToast({
							title: '请先实名认证!',
							icon: 'none',
						})
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/my/realAuth',
							})
						}, 500)
						reject(res.data.msg)
					}
				} else {
					uni.showToast({
						title: '接口请求失败' + res.statusCode,
						icon: 'none',
					})
				}
			},
			fail: res => {
				uni.showToast({
					title: '服务器请求异常',
					icon: 'none',
				})
			},
			complete: () => {},
		})
	})
}
